package org.example.course.controller;

import org.example.course.common.DataGridView;
import org.example.course.common.ResultObj;
import org.example.course.common.utils.StringUtils;
import org.example.course.domain.Check;
import org.example.course.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Classname ChecksController
 * @Description 考核环节
 * @Date 2020/5/8 21:26
 * @Created by
 */
@RestController
@RequestMapping("checks")
public class ChecksController {

    @Autowired
    private CheckService service;


    /**
     * 创建
     *
     * @param check
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.POST)
    public ResultObj create(Check check) {
        if (check == null) {
            return ResultObj.CREATE_ERROR;
        }
        if (service.create(check)) {
            return ResultObj.CREATE_SUCCESS;
        }
        return ResultObj.CREATE_ERROR;
    }


    /**
     * 创建
     *
     * @param check
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResultObj update(Check check) {
        if (check == null) {
            return ResultObj.UPDATE_ERROR;
        }
        if (service.update(check)) {
            return ResultObj.UPDATE_SUCCESS;
        }
        return ResultObj.UPDATE_ERROR;
    }


    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public ResultObj delete(@PathVariable String id) {
        if (!StringUtils.isNumeric(id)) {
            return ResultObj.COMMON_WARN_ID_SHOULD_INTEGER;
        }
        if (service.delete(id)) {
            return ResultObj.DELETE_SUCCESS;
        }
        return ResultObj.DELETE_ERROR;
    }

    /**
     * 查询动态列表头
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "findCheckCols/{id}", method = RequestMethod.GET)
    public DataGridView findCheckCols(@PathVariable String id) {
        DataGridView dataGridView = service.findCheckCols(id);
        return dataGridView;
    }


    /**
     * 是否设置平均成绩
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "findCheckColsIsOk/{id}", method = RequestMethod.GET)
    public ResultObj findCheckColsIsOk(@PathVariable String id) {
        if (!StringUtils.isNumeric(id)) {
            return ResultObj.COMMON_WARN_ID_SHOULD_INTEGER;
        }
        if (service.findCheckColsIsOk(id)) {
            return ResultObj.OPERATE_SUCCESS;
        }
        return ResultObj.OPERATE_ERROR;

    }


}
